package com.yzc.controller;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.yzc.pojo.Pve;
import com.yzc.pojo.Tour;
import com.yzc.service.PveService;
import com.yzc.service.TourService;
import com.yzc.util.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/tour")
public class TourController {

    private static final Marker LOG_MARKER = MarkerFactory.getMarker("LOG");
    @Autowired
    private TourService tourService;
    @Autowired
    private PveService pveService;


    @PostMapping("/selectBypvenameInfo")
    public List<Pve> selectBypvename(Pve pvename) {
        log.info(LOG_MARKER, "浏览了" + pvename + "景点");
        return pveService.selectBypvename(pvename);
    }

    @PostMapping("/selectBypvenameOnaddress")
    public List<Pve> selectBypvenameOnaddress() {
        log.info(LOG_MARKER, "selectBypvenameOnaddress");
        return pveService.selectBypvenameOnaddress();
    }

    @PostMapping("/loadAllTourData")
    public List<Tour> loadAll() {
        log.info(LOG_MARKER, "loadAllTourData");
        return tourService.loadAllTourData();
    }


    @PostMapping("/selectBytournameInfo")
    public List<Tour> selectInfos(@RequestBody Tour tourname) {
        log.info(LOG_MARKER, "selectBytournameInfo");
        return tourService.selectInfos(tourname);
    }


    @DeleteMapping("/deleteInfos")
    public ResultData deleteInfos(@RequestParam("tourid") int tourid) {
        tourService.deleteInfos(tourid);
        log.info(LOG_MARKER, "删除了一个景点");
        return ResultData.success();
    }

    @PostMapping("/saveInfos")
    public ResultData saveInfos(@RequestBody Tour tour) {
        tourService.saveInfos(tour);
        log.info(LOG_MARKER, "saveInfos");
        return ResultData.success();
    }


    @PostMapping("/updateInfos")
    public ResultData updateInfos(@RequestBody Tour tour) {
        tourService.updateInfos(tour);
        log.info(LOG_MARKER, "更新景点信息");
        return ResultData.success();
    }

    @GetMapping("/getTourid")
    public Tour getTourid(@RequestParam("tourid") Integer tourid) {
        log.info(LOG_MARKER, "getTourid");
        return tourService.getTourid(tourid);
    }
}
